package com.example.hospitalapp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

public class DoctorMedicalRecordActivityAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<MedicalRecord> medicalRecords;
    private ArrayList<Patient> patients;

    public DoctorMedicalRecordActivityAdapter(Context context, ArrayList<MedicalRecord> medicalRecords, ArrayList<Patient> patients) {
        this.context = context;
        this.medicalRecords = medicalRecords;
        this.patients = patients;
    }

    @Override
    public int getCount() {
        return medicalRecords.size();
    }

    @Override
    public Object getItem(int position) {
        return medicalRecords.get(position);
    }

    @Override
    public long getItemId(int position) {
        return medicalRecords.get(position).getRecordId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_doctor_medical_record, parent, false);
        }

        MedicalRecord medicalRecord = medicalRecords.get(position);
        Patient patient = patients.get(position);

        TextView txtVisitDate = convertView.findViewById(R.id.txtVisitDate);
        TextView txtDiagnosis = convertView.findViewById(R.id.txtDiagnosis);
        TextView txtTreatment = convertView.findViewById(R.id.txtTreatment);
        TextView txtPatientName = convertView.findViewById(R.id.txtPatientName);
        TextView txtPatientPhone = convertView.findViewById(R.id.txtPatientPhone);

        // 设置病历信息
        txtVisitDate.setText("就诊日期: " + medicalRecord.getVisitDate());
        txtDiagnosis.setText("诊断: " + medicalRecord.getDiagnosis());
        txtTreatment.setText("治疗方案: " + medicalRecord.getTreatment());

        // 设置病人信息
        return convertView;
    }
}
